package org.example.Servlet.PersonServlet;

import org.example.Dao.TopicDao;
import org.example.entity.Topic;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/person/index")
public class PersonIndexServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        TopicDao topicDao = new TopicDao();
        HttpSession session = req.getSession();
        // 准备好主题集合
        List<Topic> topicList = null;
        try {
            topicList = topicDao.getTopicList();
            System.out.println("topicList ==> " + topicList.toString());
            session.setAttribute("topicList", topicList);
        } catch (Exception e) {
            System.out.println("to person index error ==> " + e.getMessage());
        }

        resp.sendRedirect(req.getContextPath() + "/views/user/index.jsp");
    }
}
